#[derive(Debug)]
enum WebEvent {
    PageLoad,
    PageUnload,
    KeyPress(char),
    Paste(String),
    Click { x: i64, y: i64 },
}

fn inspect(event: WebEvent){
    match event {
        WebEvent::PageLoad => println!("page load"),
        WebEvent::PageUnload => println!("page unload"),
        WebEvent::KeyPress(c) => println!("pressed `{}`.", c),
        WebEvent::Paste(s) => println!("pasted \"{}\".", s),
        WebEvent::Click {x, y} => {
            println!("Clickicked at x={}, y={}.", x, y);
        },
    }
}
fn web_event_use(){
    let pressed = WebEvent::KeyPress('x');
    inspect(pressed);

    let pasted = WebEvent::Paste("my text".to_owned());
    inspect(pasted);

    let click = WebEvent::Click { x: 20, y: 80};
    inspect(click);

    let load = WebEvent::PageLoad;
    inspect(load);

    let unload = WebEvent::PageUnload;
    inspect(unload);
}


//type alias example 
enum VeryVerboseEnumOfThingsToDoWithNumbers {
    Add,
    Substract,
}

// Self : alias in impl for the Enum name
impl VeryVerboseEnumOfThingsToDoWithNumbers {
    fn run(&self, x: i32, y: i32) -> i32 {
        match self {
            Self::Add => x + y, 
            Self::Substract => x - y,
        }
    }
}

type Operations = VeryVerboseEnumOfThingsToDoWithNumbers;

fn type_alias(){
    let x = Operations::Add;
    println!("1 + 2 = {}", x.run(1, 2));
    
    let y = Operations::Substract;
    println!("2 - 1 = {}", y.run(2, 1));
}



pub mod enum_use; // in subdir
pub mod c_like; //in subdir
pub mod linked_list;

pub fn main(){
    web_event_use();
    type_alias();

    println!("......sub mod enum_use:");
    enum_use::main();
    c_like::main();
    linked_list::main();
}
